package com.gouqi.mall.controller;

import com.gouqi.mall.domain.Enterprise;
import com.gouqi.mall.domain.EnterpriseProduct;
import com.gouqi.mall.service.EnterpriseProductService;
import com.gouqi.mall.service.EnterpriseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@CrossOrigin
@Api(basePath = "/api/v1", value = "企业产品信息", description = "操作企业生产产品信息")
@Component
@RestController
@RequestMapping(value = "/enterprise/product")
public class EnterpriseProductController extends BaseController{

    @Autowired
    @Qualifier("enterpriseProductServiceImpl")
    private EnterpriseProductService service;

    @ResponseBody
    @RequestMapping(value = "/addProduction.do",method = RequestMethod.POST, produces = "application/json")
    @ApiOperation(value = "新增企业产品信息",notes = "新增企业产品信息",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",name = "token",value = "用户token",required = true,dataType = "String")
    })
    public String addProduction(@RequestHeader String token,@RequestBody @Valid EnterpriseProduct product){
        return service.addProduction(product);
    }

    @ResponseBody
    @RequestMapping(value = "/updateProduction.do",method = RequestMethod.PUT, produces = "application/json")
    @ApiOperation(value = "更新企业产品信息",notes = "更新企业的产品信息",httpMethod = "PUT")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",name = "token",value = "用户token",required = true,dataType = "String")
    })
    public String updateProduction(@RequestHeader String token,@RequestBody @Valid EnterpriseProduct product){
        return service.updateProduction(product);
    }

    @ResponseBody
    @RequestMapping(value = "/deleteProduction.do",method = RequestMethod.DELETE, produces = "application/json")
    @ApiOperation(value = "删除企业产品信息",notes = "删除一个企业产品信息",httpMethod = "DELETE")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",name = "token",value = "用户token",required = true,dataType = "String"),
            @ApiImplicitParam(paramType = "query",name = "id",value = "企业产品信息id",required = true,dataType = "Integer"),
    })
    public String deleteProduction(@RequestHeader String token,@RequestParam Integer id){
        return service.deleteProduction(id);
    }

    @ResponseBody
    @RequestMapping(value = "/queryProduction.do",method = RequestMethod.GET, produces = "application/json")
    @ApiOperation(value = "搜索企业产品信息",notes = "搜索一家企业产品信息，通过产品名称来搜索",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",name = "token",value = "用户token",required = true,dataType = "String"),
            @ApiImplicitParam(paramType = "query",name = "by",value = "通过什么查找",required = true,dataType = "String",defaultValue = "name"),
            @ApiImplicitParam(paramType = "query",name = "name",value = "企业产品名称",required = true,dataType = "String")
    })
    public String queryProduction(@RequestHeader String token,@RequestParam String name){
        return service.queryProduction(name);
    }
}
